package vn.com.fsoft.action;

import java.util.List;

import vn.com.fsoft.business.IAddressBussiness;
import vn.com.fsoft.business.impl.AddressBussiness;
import vn.com.fsoft.model.entities.AddressNew;

import com.opensymphony.xwork2.ActionSupport;

public class AddressAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1791155290134174139L;
	private static IAddressBussiness aBussiness;
	public AddressAction() {
		aBussiness= new AddressBussiness();		
	}

	@Override
	public String execute() throws Exception {
		if(currentPage==1) {
			previewPage = totalPage;
			nextPage = currentPage + 1;
		} else if(currentPage > totalPage){
			currentPage = 1;
		} else  if(currentPage < totalPage && currentPage > 1) {
			previewPage = currentPage - 1;
			nextPage = currentPage + 1;
		} else if( currentPage == totalPage) {
			previewPage = nextPage = 1;
		}
		listAddress = aBussiness.lookUpAddress(postCode, street, townName,
				pageSize, currentPage);
		totalPage = aBussiness.getTotalPage();
		return SUCCESS;
	}

	/* Getter && setter */
	private String postCode = "";
	private String street = "";
	private String townName = "";
	private List<AddressNew> listAddress;
	private static int pageSize = 5;
	private static int currentPage=1;
	private static int nextPage;
	private static int previewPage;
	private static int totalPage;

	public String getPostCode() {
		return postCode;
	}

	public void setPostCode(String postCode) {
		this.postCode = postCode;
	}

	public String getStreet() {
		return street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	public String getTownName() {
		return townName;
	}

	public void setTownName(String townName) {
		this.townName = townName;
	}

	public List<AddressNew> getListAddress() {
		return listAddress;
	}

	public void setListAddress(List<AddressNew> listAddress) {
		this.listAddress = listAddress;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getNextPage() {
		return nextPage;
	}

	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	public int getPreviewPage() {
		return previewPage;
	}

	public void setPreviewPage(int previewPage) {
		this.previewPage = previewPage;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public void setPageSize(int pageSize) {
		if(pageSize > 0)
			this.pageSize = pageSize;
	}

}
